﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class lichvn_namsg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.calNamSgVn.Visible = false;
            this.lblError.Visible = false;
            this.lblDateShow.Text = DateTime.Now.ToShortDateString();
            //this.lblDateShow.Text = "06/25/2010";
            LoadFilm();
        }
    }
    protected void calNamSGVnButton_Click(object sender, ImageClickEventArgs e)
    {
        if (this.calNamSgVn.Visible == true)
            this.calNamSgVn.Visible = false;
        else
        {
            this.calNamSgVn.SelectedDate = DateTime.Parse(this.lblDateShow.Text);
            this.calNamSgVn.Visible = true;
        }
    }
    protected void calNamSgVn_SelectionChanged(object sender, EventArgs e)
    {
        this.lblDateShow.Text = this.calNamSgVn.SelectedDate.ToShortDateString();
        LoadFilm();
        this.calNamSgVn.Visible = false;
    }
    private void LoadFilm()
    {
        FilmSchedule filmSchedule = new FilmSchedule();
        DataSet ds = new DataSet();
        ds = filmSchedule.LoadFilmSchedule(Convert.ToDateTime(this.lblDateShow.Text),7);
        this.grdFilmSchedule.DataSource = ds;
        this.grdFilmSchedule.DataBind();
        if (ds == null || ds.Tables[0].Rows.Count == 0)
        {
            this.lblError.Text = "Không có lịch chiếu phim trong ngày được chọn";
            this.lblError.Visible = true;
            return;
        }
        else
        {
            this.lblError.Visible = false;
            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
            {
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    if (i == 0)
                    {
                        this.grdFilmSchedule.Rows[j].Cells[i].CssClass = "style7";

                    }
                    else
                    {
                        if (ds.Tables[0].Rows[j][i].ToString() != "" && ds.Tables[0].Rows[j][i].ToString() != null)
                            this.grdFilmSchedule.Rows[j].Cells[i].Text = String.Format("{0:HH:mm}", Convert.ToDateTime(this.grdFilmSchedule.Rows[j].Cells[i].Text));
                        this.grdFilmSchedule.Rows[j].Cells[i].CssClass = "style6";
                        this.grdFilmSchedule.Rows[j].Cells[i].Width = 108;
                    }
                }
            }
            for (int i = 1; i < ds.Tables[0].Columns.Count; i++)
            {
                this.grdFilmSchedule.HeaderRow.Cells[i].CssClass = "style6";
                this.grdFilmSchedule.HeaderRow.Cells[i].Text = "Suất " + i.ToString();
            }
            this.grdFilmSchedule.HeaderRow.Cells[0].Style.Add("text-align", "center");
            this.grdFilmSchedule.HeaderRow.Cells[0].Text = "Tên Phim";
            this.grdFilmSchedule.HeaderRow.Cells[0].CssClass = "style7";
        }
    }
}
